package ota;

public class MyByte
{
    public static String[] byte2String;
    
    public static String buffer2String(final byte[] array) {
        if (array == null) {
            return "";
        }
        final StringBuffer sb = new StringBuffer();
        for (int length = array.length, i = 0; i < length; ++i) {
            sb.append((Integer.toHexString(array[i])).toUpperCase().trim() + " ");
        }
        return sb.toString();
    }
    
    public static String byte2String(final byte b) {
        return (Integer.toHexString(b)).trim().toUpperCase();
    }
    
    public static String byte2String(final int n) {
        return (Integer.toHexString(n)).trim().toUpperCase();
    }
    
    public static int byteToInt(final byte b) {
        if (b >= 0) {
            return b;
        }
        return b + 256;
    }
    
    public static int byteToInt(final int n) {
        if (n >= 0) {
            return n;
        }
        return n + 256;
    }

    public static byte[] intToByteArray(int i) {
        byte[] result = new byte[4];
        result[0] = (byte) ((i >> 24) & 0xFF);
        result[1] = (byte) ((i >> 16) & 0xFF);
        result[2] = (byte) ((i >> 8) & 0xFF);
        result[3] = (byte) (i & 0xFF);
        return result;
    }
    
    
}
    